/* $Id: BulletedTextListAdapter.java 88 2008-01-19 15:49:18Z osborn.steven $
 * 
 * Undroid Package Manager
 *
 * Copyright 2007 Steven Osborn
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */
package com.bitsetters.android.common;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;


/**
 * 
 * @author Steven Osborn - http://steven.bitsetters.com
 */
public class BulletedTextListAdapter extends BaseAdapter {

    /**
     * Remember our context so we can use it when constructing views.
     */
    private Context mContext;

    private List<BulletedText> mItems;
    public static final String TAG = "UNDROID[BulletedTextListAdapter]";

    /**
     * 
     * @param context
     */
    public BulletedTextListAdapter(Context context) {
        mContext = context;
        mItems  = new ArrayList<BulletedText>();
    }

    /**
     * 
     * @param bt
     */
    public void addItem(BulletedText bt) {
        mItems.add(bt);
    }

    /**
     * 
     * @param bti
     */
    public void setListItems(List<BulletedText> bti) {
        mItems = bti;
    }

    /**
     * The number of items in the
     */
    public int getCount() {
        return mItems.size();
    }

    /**
     * 
     */
    public Object getItem(int position) {
        return mItems.get(position);
    }

    /**
     * 
     */
    public boolean areAllItemsSelectable() {
        return false;
    }

    /**
     * 
     */
    public boolean isSelectable(int position) {
        return mItems.get(position).isSelectable();
    }

    /**
     * Use the array index as a unique id.
     */
    public long getItemId(int position) {
        return position;
    }

    /**
     * Make a BulletedTextView to hold each row.
     */
    public View getView(int position, View convertView, ViewGroup parent) {
        BulletedTextView btv;
        if (convertView == null) {
            if(mItems.get(position).getSubText().length() > 0) {
                btv = new BulletedTextView(mContext, mItems.get(position).getText(),
                        mItems.get(position).getBullet(),mItems.get(position).getSubText());
            } else {
                btv = new BulletedTextView(mContext, mItems.get(position).getText(),
                        mItems.get(position).getBullet(),null);
            }
        } else {
            btv = (BulletedTextView) convertView;
            btv.setText(mItems.get(position).getText());
            btv.setBullet(mItems.get(position).getBullet());
        }

        return btv;
    }
}
